import React, { Component } from 'react'

export default class Updatestu extends Component {
    handleUpdate = () => {
        let {nameInput,ageInput,sexInput} = this;
        let name = nameInput.value;
        let age = ageInput.value;
        let sex = sexInput.checked?'male':'female';
        this.props.updateStu({name,age,sex});
        nameInput.value='';ageInput.value='';
    }
    setNameRef = (ele) => {
        this.nameInput=ele
    }
    setAgeRef = (ele) => {
        this.ageInput=ele
    }
    getSexMale = (ele) => {
        this.sexInput=ele;
    }
    // getSexFemale = (ele) => {
    //     this.sexFemaleInput=ele;
    // }
    render() {
        let {stuInfo} = this.props;
        // stuInfo==''? this.sexInput.defaultChecked='true':
        // stuInfo.gender == 'male'? '':
        // this.sexFemaleInput.defaultChecked='true';
        return (
            <div>
                <h1>修改学生</h1>
                <p><label>姓名： </label><input ref={this.setNameRef} type="text" name="" defaultValue={stuInfo?stuInfo.name:''}/></p>
                <p><label>年龄： </label><input ref={this.setAgeRef} type="text" name="" defaultValue={stuInfo?stuInfo.age:''}/></p>
                <p>
                    <label htmlFor='gender'>性别：</label>
                    男<input ref={this.getSexMale} type='radio' name="gender"  defaultChecked='true'/>
                    女<input type="radio" name="gender" />
                </p>
                <button onClick={this.handleUpdate}>修改</button>
            </div>
        )
    }

}
